<template>
  <div>
    <BreakSpace label="基本信息" :containerStyle="{ marginBottom: '15px' }" />
    <FormPanel ref="formPanel1" :list="formInfoList" labelWidth="100" :formType="type" :isSubmitBtn="false" />

    <BreakSpace label="价格信息" :containerStyle="{ marginBottom: '15px' }" />
    <FormPanel ref="formPanel" :list="formPriceList" labelWidth="100" :formType="type" :isSubmitBtn="false" />

    <BreakSpace label="替换件信息" :containerStyle="{ marginBottom: '15px' }"  />
    <FilterTable
      ref="table"
      :columns="subPartColumns"
      :fetchapi="subPartList"
      :params="subPartParams"
      height="auto"
      :datakey="'records'"
      :isSelectColumn="false"
      :isToperInfo="false"
      :isColumnFilter="false"
      :isPagination="false"
      :onRowSelectChange="selectChange"
      :onColumnsChange="columns => (this.subPartColumns = columns)"
    >
    </FilterTable>

    <div :style="{ textAlign: 'center' }">
      <el-button @click="closeDialog" style="margin-top: 10px;">返 回</el-button>
    </div>
  </div>
</template>

<script>
import {getSubPartList} from '@/api/graphic/hotspotEdit/index.js';
import { dictionary } from '@/utils/dictMixin';
import { positiveInteger } from '@/utils/validate';

export default {
  name: 'HotsPotPartInfo',
  mixins: [dictionary],
  components: {},
  props: {
    type: { type: String, default: 'add' },
    rowData: { type: Object, default: () => ({}) }
  },
  data() {
    return {
      formInfoList: this.createFormInfoList(),
      formPriceList: this.createFormPriceList(),
      subPartColumns: this.createSubPartTable(),
      subPartList: getSubPartList,
      priceParams: { partInfoId: '', xtlxdm: 'LS' },
      subPartParams: { mainPartId: '' },
      showSubPart: false
    };
  },
  created() {
    this.priceParams.partInfoId = this.rowData.id;
    this.subPartParams.mainPartId = this.rowData.id;
    this.init(this.rowData);
  },
  methods: {
    selectChange(val) {
      this.rowSelectData = val;
    },
    init(data) {
      this.formInfoList.forEach(x => {
          if(x.fieldName=='bjsycx' && this.rowData[x.fieldName] && this.rowData[x.fieldName] !=null ){
            let initValue = this.rowData[x.fieldName].split(";");
            x.initialValue = initValue;
          }else{
            x.initialValue = this.rowData[x.fieldName];
          }
      });
      this.formPriceList.forEach(x => {
        if (x.fieldName == 'bjjgbz') {
          x.initialValue = this.rowData[x.fieldName];
        } else {
          x.initialValue = this.rowData[x.fieldName].toFixed(2);
        }
      });
    },
    createFormInfoList() {
      return [
        { type: 'INPUT', label: '备件代码', fieldName: 'bjxmbh', disabled: true },
        { type: 'INPUT', label: '备件名称', fieldName: 'bjzwmc', disabled: true },
        { type: 'MULTIPLE_SELECT', label: '适用车型', fieldName: 'bjsycx', itemList: [] },
        { type: 'INPUT', label: '备件类别', fieldName: 'partTypeName', disabled: true },
        { type: 'INPUT', label: '单位', fieldName: 'bjdanw', disabled: true },
        { type: 'SELECT', label: '是否紧急件', fieldName: 'bjdebz', itemList: this.createDictList('1004') ,clearable:false},
        { type: 'INPUT', label: '销售包装量', fieldName: 'bjxszx',initialValue:1 },
        { type: 'SELECT', label: '销售标识', fieldName: 'bjxsbz', itemList: this.createDictList('1004') ,clearable:false},
        { type: 'SELECT', label: '是否特殊件', fieldName: 'bjtsbz', itemList: this.createDictList('1004') ,clearable:false},
        { type: 'INPUT', label: '备注', fieldName: 'remark', selfCols: 3, maxlength: 150 }
      ];
    },
    createFormPriceList() {
      return [
        { type: 'INPUT', label: '服务商进价', fieldName: 'xs', disabled: true },
        { type: 'INPUT', label: '终端销售价', fieldName: 'ls', disabled: true, },
        { type: 'INPUT', label: '备注', fieldName: 'bjjgbz' ,maxlength: 150}
      ];
    },
    createSubPartTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '替换件代码', dataIndex: 'replacePartCode', sorter: true },
        { title: '替换件名称',  dataIndex: 'replacePartName', sorter: true },
        { title: '替换件价格',  dataIndex: 'replacePartPrice', sorter: true }
      ];
    },
    openAddDialog() {
      this.showSubPart = true;
    },
    closeHandler(val) {
      this.showSubPart = false;
      this.subPartParams = { ...this.subPartParams };
    },
    closeDialog(param) {
      this.$emit('close', { visible: false, type: param });
    }
  }
};
</script>

<style scoped></style>
